package com.zoffy.catdiarybackend.model.vo;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.zoffy.catdiarybackend.model.entity.Article;
import lombok.Data;

import java.util.Date;
@Data
public class ArticleTinyVo {
    private Long id;

    /**
     * 标题
     */
    @TableField(value = "title")
    private String title;


    /**
     * 描述
     */
    @TableField(value = "description")
    private String description;

    /**
     * 类型(Markdown/draw)
     */
    @TableField(value = "type")
    private String type;

    private Permissions permissions;
    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private Date createTime;
    public static ArticleTinyVo obj2TinyVo(Article article){
        ArticleTinyVo articleTinyVo=new ArticleTinyVo();
        articleTinyVo.setId(article.getId());
        articleTinyVo.setTitle(article.getTitle());
        articleTinyVo.setType(article.getType());
        articleTinyVo.setDescription(article.getDescription());
        articleTinyVo.setCreateTime(article.getCreateTime());
        Permissions permissions = JSON.parseObject(article.getPermissions(),Permissions.class);
        permissions.setCollaborators(null);
        articleTinyVo.setPermissions(permissions);
        return articleTinyVo;
    }


    private static final long serialVersionUID = 1L;
}
